package com.dindang.propertyfee.mvp.ui.adapter.custom;

import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dindang.propertyfee.R;
import com.dindang.propertyfee.app.utils.TextViewUtils;
import com.dindang.propertyfee.mvp.model.entity.PropertyCharge;

import java.util.List;

/**费用明细适配器*/
public class PaymentDetailViewAdapter extends RecyclerView.Adapter<PaymentDetailViewAdapter.ViewHolder> {
    List<PropertyCharge.RecordDetail> list;
    OnPaymentDetailListener listener;
    boolean isDetailVisibility;
    public PaymentDetailViewAdapter(List<PropertyCharge.RecordDetail> list, OnPaymentDetailListener listener) {
        this.list = list;
        this.listener = listener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.propertyfee_item_payment_detail_cost, parent, false);
        PaymentDetailViewAdapter.ViewHolder viewHolder = new PaymentDetailViewAdapter.ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        PropertyCharge.RecordDetail costItem = list.get(position);
        holder.tvCostItem.setText("费用名称: " + costItem.c_fee_type_name);
        holder.tvCost.setText("已收金额: " + TextViewUtils.getAmount3(costItem.c_paid_amount));
        if(isDetailVisibility) {
            holder.view_detail.setVisibility(View.VISIBLE);
        }else{
            holder.view_detail.setVisibility(View.GONE);
        }
        holder.tvDosage.setText("用        量: " + costItem.c_quantity);
        holder.tvUnitPrice.setText("单        价: " + TextViewUtils.getAmount(costItem.c_price));
        holder.tvReceivableDate.setText("应收日期: " + costItem.d_create_billing_date);
        holder.tvDataInterval.setText("费用期间: " + costItem.d_create_billing_date + "~" + costItem.d_end_billing_date);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void setIsDetailVisibility(boolean isDetailVisibility) {
        this.isDetailVisibility = isDetailVisibility;
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout clCostItem;
        TextView tvCostItem;
        TextView tvCost;
        ConstraintLayout view_detail;

        TextView tvDosage;
        TextView tvUnitPrice;
        TextView tvReceivableDate;
        TextView tvDataInterval;
        ViewHolder(View itemView) {
            super(itemView);
            clCostItem = itemView.findViewById(R.id.propertyfee_cl_cost_item);
            tvCostItem = itemView.findViewById(R.id.propertyfee_tv_cost_item);
            tvCost = itemView.findViewById(R.id.propertyfee_tv_cost);
            view_detail = itemView.findViewById(R.id.propertyfee_view_detail);

            tvDosage = itemView.findViewById(R.id.propertyfee_tv_dosage);
            tvUnitPrice = itemView.findViewById(R.id.propertyfee_tv_unit_price);
            tvReceivableDate = itemView.findViewById(R.id.propertyfee_tv_receivable_date);
            tvDataInterval = itemView.findViewById(R.id.propertyfee_tv_data_interval);
        }
    }

    public interface OnPaymentDetailListener{
        void onClick(int position);
    }

}